﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Tbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;

namespace HKEA.CMS.Core.BLL.Tbl
{
    public class tblBrand_ProdCatBLL
    {
        private  ItblBrand_ProdCat IDAL;
        public tblBrand_ProdCatBLL()
        {
            IDAL = DataAccess.CreateItblBrand_ProdCat();
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static tblBrand_ProdCatBLL GetInstance()
        {
            return new tblBrand_ProdCatBLL();
        }
        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(tblBrand_ProdCat ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret= IDAL.InsertENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 对某一个Brand的ProductSubCat进行修改(增加、删除)
        /// </summary>
        /// <param name="toAddList">需要被添加关联的SubCatUIDList</param>
        /// <param name="toDelList">需要被删除关联的SubCatUIDList</param>
        /// <param name="brandUID">被操作的BrandUID</param>
        /// <param name="LastModifyBy">LastModifyBy</param>
        /// <returns></returns>
        public int SaveList(List<int> toAddList, List<int> toDelList, int brandUID, string LastModifyBy)
        {
            int ret = 0;
            if (brandUID > 0)
            {
                try { ret = IDAL.SaveList(toAddList, toDelList, brandUID, LastModifyBy); }
                catch (Exception er) { throw; }
            }
            return ret;
        }
        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int DeleteENT(tblBrand_ProdCat ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int UpdateENT(tblBrand_ProdCat ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<tblBrand_ProdCat> GetListByENT(tblBrand_ProdCat ent,PageParam param, string strPropertyName,string strOrderBy)
        {
            List<tblBrand_ProdCat> list=new List<tblBrand_ProdCat>();
            if (ent != null && param != null)
            {
                try
                {
                    list= IDAL.GetListByENT(ent,param,strPropertyName,strOrderBy);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        public List<mtblProductSubCat> GetSubCatListByBrandUID(int uid)
        {
            List<mtblProductSubCat> list = new List<mtblProductSubCat>();
            if (uid > 0)
            {
                try { list = IDAL.GetSubCatListByBrandUID(uid); }
                catch (Exception er) { throw; }
            }
            return list;
        }
        public List<mtblProductSubCat> GetSubCatListByBrandUID(int uid, List<int> withOutList)
        {
            List<mtblProductSubCat> list = new List<mtblProductSubCat>();
            if (uid > 0)
            {
                try { list = IDAL.GetSubCatListByBrandUID(uid,withOutList); }
                catch (Exception er) { throw; }
            }
            return list;
        }

        /// <summary>
        /// 根据条件得到符合条件的结果集，不带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<tblBrand_ProdCat> GetListByENT(tblBrand_ProdCat ent)
        {
            List<tblBrand_ProdCat> list = new List<tblBrand_ProdCat>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }
        public tblBrand_ProdCat GetEntity(tblBrand_ProdCat ent)
        {
            return GetListByENT(ent).FirstOrDefault();
        }
        /// <summary>
        /// 根据条件得到符合条件的记录条数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int GetCountByENT(tblBrand_ProdCat ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 判断是否已存在符合条件的记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public bool IsExist(tblBrand_ProdCat ent)
        {
            bool ret = false;
            if (ent != null)
            {
                if (GetCountByENT(ent) > 0)
                    ret = true;
            }
            return ret;
        }
        public List<tblBrand_ProdCat> GetList(tblBrand_ProdCat ent, List<int> withOutList)
        {
            List<tblBrand_ProdCat> list = new List<tblBrand_ProdCat>();
            try { list = IDAL.GetList(ent, withOutList); }
            catch (Exception er) { throw; }
            return list;
        }
    }
}
